package org.saxion.saktiehuis;

import org.saxion.saktiehuis.model.UserSession;
import org.saxion.saktiehuis.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ProductController {

	private static final Logger logger = LoggerFactory
			.getLogger(ProductController.class);

	@Autowired
	ProductService productService;
	@Autowired
	UserSession session;

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String overview(Model model) {
		model.addAttribute("products", productService.getAllProducts());
		return "overview";
	}

	@RequestMapping(value = "/categorie/{id}", method = RequestMethod.GET)
	public String category(@PathVariable Long id, Model model) {
		model.addAttribute("products",
				productService.getProductsByCategoryId(id));
		return "overview";
	}

	@RequestMapping(value = "/product/{id}", method = RequestMethod.GET)
	public String product(@PathVariable Long id, Model model) {
		model.addAttribute("product", productService.getProductById(id));
		return "product";
	}

}
